package com.opencloud.iot.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotConfigs;
import com.opencloud.iot.client.model.entity.IotRecorders;
import com.opencloud.iot.provider.mapper.IotConfigsMapper;
import com.opencloud.iot.provider.mapper.IotRecordersMapper;
import com.opencloud.iot.provider.service.IotConfigsService;
import com.opencloud.iot.provider.service.IotRecordersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 进出记录操作
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotConfigsServiceImpl implements IotConfigsService {

    @Autowired
    private IotConfigsMapper iotConfigsMapper;

    @Override
    public IPage<IotConfigs> findListPage(PageParams pageParams) {
        QueryWrapper<IotConfigs> queryWrapper = new QueryWrapper();
        queryWrapper.lambda();
        return iotConfigsMapper.selectPage(new Page(pageParams.getPage(),pageParams.getLimit()),queryWrapper);
    }

    @Override
    public IotConfigs findConfigByKey(String key) {
        QueryWrapper<IotConfigs> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(key),IotConfigs::getConfigKey,key)
                .orderByDesc(IotConfigs::getConfigId);
        return iotConfigsMapper.selectOne(queryWrapper);
    }

}
